<?php
include('../Lib/php/conex.php');
$link= conectaSQL("influenza","inf123456","influenza");
include('../Lib/php/fechas.php');

import_request_variables("gP");

if ($sector > 1) $filtroSector = " and a.id_sector = $sector ";
if ($nEstado > 0 and $nEstado < 99) $filtroEstado = " and nEntidad = $nEstado";

//$nTipoPaciente = "nTipoPaciente in (1,2)";

// CONSTRUYE QUERY
//---------------------------------------------------------------------------------------------------------
$sql ="SELECT  a.nSexo,count(*)
		FROM dat_generales a 
		left join (select id_generales from dat_registro a left join dat_generales b ON (a.id_generales = b.id_principal)
		where $tipoPaciente and nStatus = 1 $filtroSector $filtroEstado
			group by id_generales)b ON (a.id_principal = b.id_generales)
		WHERE a.nStatus = 1
		group by a.nSexo";

$resultado = mssql_query($sql,$link);

$i=0;
while ($filas = mssql_fetch_row($resultado)){
	$data[$i][0] = $filas[0];	
	$data[$i][1] = $filas[1];	
	$data[$i][2] = $filas[2];			
	$data[$i][3] = $filas[3];				
	$i++;
}			

//print_r($data);
//return;
include('../Lib/php/phplot-5/phplot.php');
$plot = new PHPlot(400, 300);

$which_btype = "full";				//Plot Border  // plotleft,plotright,both,full,none, 

$plot->SetDataType('text-data-single');
$plot->SetDataValues($data);
$plot->SetPlotType("pie");
$plot->SetTTFPath(getcwd());
$plot->SetDefaultTTFont("arial.ttf");	
$plot->SetTitle("CASOS DE ETI/IRAG NACIONAL POR GENERO");
$plot->SetLegend(array("HOMBRES","MUJERES"));	
$plot->SetXDataLabelAngle(90);	
$plot->SetDataColors(array('yellow','red', 'green', 'blue','SlateBlue'));
	
 
// Coloca la escala del eje Y y el tipo de incremento
$plot->SetXLabelAngle(90);	
$plot->SetFont('title','',8);	

//$plot->SetXTickIncrement(1);
 
 //Other settings
$plot->SetBackgroundColor("#FfFFFF");		
$plot->SetTextColor("blue");
$plot->SetGridColor("black");
$plot->SetLightGridColor(array(175,175,175));
$plot->SetTickColor("black");
$plot->SetTitleColor("navy"); // Can be array or name
$plot->SetPlotBorderType($which_btype);		


$plot->DrawGraph();

?>